package cn.cs.controller;

import cn.cs.common.Dto;
import cn.cs.common.DtoUtil;
import cn.cs.pojo.Shop;
import cn.cs.service.ShopService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/shop")
public class ShopController {
    @Resource
    private ShopService shopService;

    /****
     * 查询附近商铺
     * @return
     */
    @RequestMapping(value = "/wxApi/shopList")
    @ResponseBody
    public Dto shopList(String lon,//经度
                        String lat,//纬度
                        String typeId,//产品类别Id
                        String key,//搜索关键字
                        String area,//区域Id
                        int pageNumber,//分页 开始数默认0
                        int pageSize//分页条数
    ) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("lon", lon);
        map.put("lat", lat);
        map.put("typeId",typeId);
        map.put("key",key);
        map.put("area",area);
        map.put("pageNumber", pageNumber);
        map.put("pageSize",pageSize);


        List<Shop> list = shopService.getShopList(map);
        for(Shop a:list){
            String typeNames = a.getTypeName().toString().replace("[", "").replace("]", "").replace(",", " ");
            a.setTypeNameToString(typeNames);
        }
        return DtoUtil.returnDataSuccess(list);
    }


    /**
     * 根据经销商邀请码查询附近店铺
     * @param pageNumber
     * @param pageSize
     * @param code
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/wxApi/getShopByCodePage")
    public Dto getShopByCodePage(Integer pageNumber, Integer pageSize, String code) throws Exception {
        Map<String, Object> param = new HashMap<>();
        param.put("code", code);
        return DtoUtil.returnSuccess("获取成功", shopService.queryShopPageByMap(param, pageNumber, pageSize));
    }


    }








